package com.ztjava.pay.listener;

import org.apache.log4j.Logger;

import com.jfinal.aop.Duang;
import com.jfinal.kit.JsonKit;
import com.jfinal.kit.Ret;
import com.ztjava.core.Constant;
import com.ztjava.core.bean.sub.PayBean;
import com.ztjava.pay.service.PayService;
import com.ztjava.plugin.event.EventTag;
import com.ztjava.plugin.event.core.ApplicationListener;
import com.ztjava.plugin.event.core.Listener;
import com.ztjava.plugin.event.core.RequestEvent;

@Listener(tag=EventTag.PAY_INSERT)
public class InsertOrderListener implements ApplicationListener<RequestEvent>{
	private static Logger logger = Logger.getLogger(InsertOrderListener.class);
	private static PayService payService = Duang.duang(PayService.class);
	@Override
	public Ret onApplicationEvent(RequestEvent event) {
		PayBean payBean = (PayBean)event.getSource();
		Ret result = payService.insertOrder(payBean);
		logger.debug(JsonKit.toJson(payBean));
		if(result.getStr(Constant.RESULT).equals(Constant.ERROR)){
			logger.error("支付模块建单失败:"+result.getStr(Constant.MESSAGE));
			logger.error(JsonKit.toJson(payBean));
		}
		return result;
	}

}
